package cn.ziyoufa.smart.smartschool.application;

import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.widget.Toast;

import com.tencent.bugly.crashreport.CrashReport;

import java.io.IOException;
import java.security.InvalidParameterException;

import android_serialport_api.SerialPort;
import cn.ziyoufa.smart.smartschool.serialport.SerialHelper;

/**
 * 创建人 ： 赵泽东
 * 创建时间：2018/8/30
 *
 * @param
 * @param
 */
public class PasisApplication extends Application {

    private static PasisApplication mApplicaiton = null;

    public static AlarmManager am;
    public static PendingIntent pi;
    private SerialPort mSerialPort = null;

    @Override
    public void onCreate() {
        super.onCreate();
        mApplicaiton = this;
        CrashReport.initCrashReport(getApplicationContext());
    }

    public static PasisApplication getInstance(){
        return mApplicaiton;
    }

    //----------------------------------------------------关闭串口
    public void closeComPort(SerialHelper ComPort){
        if (ComPort!=null){
            ComPort.stopSend();
            ComPort.close();
        }
    }
    //----------------------------------------------------开启串口
    public void openComPort(SerialHelper ComPort){
        try
        {
            ComPort.open();
        } catch (SecurityException e) {
            ShowMessage("打开串口失败:没有串口读/写权限!");
        } catch (IOException e) {
            ShowMessage("打开串口失败:未知错误!");
        } catch (InvalidParameterException e) {
            ShowMessage("打开串口失败:参数错误!");
        }
    }

    private void ShowMessage(String sMsg)
    {
        Toast.makeText(this, sMsg, Toast.LENGTH_SHORT).show();
    }
}
